package com.wgts.wgts.mvp.view.activity.pay;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.BaseLoadMoreAdapter;
import com.wgts.wgts.mvp.view.activity.goodsinfo.JDGoodinfoActivity;
import com.wgts.wgts.netmodle.resp.SearchShopResultEntity;
import com.wgts.wgts.tools.AppInfor;
import com.wgts.wgts.tools.CustomImageView;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 *
 *
 *   data:2018/10/813:56
 *
 */public class PayResultRecycleAdapter extends BaseLoadMoreAdapter<PayResultRecycleAdapter.ViewHold> {
    private Context context;
    private List<SearchShopResultEntity.ShopList> list;

    public PayResultRecycleAdapter(Context context, List<SearchShopResultEntity.ShopList> list) {
        super(context);
        this.context = context;
        this.list = list;
    }


    @Override
    public void onBindBodyViewHolder(@NonNull ViewHold viewHolder, final int i) {
        CustomImageView.getInstance().customImage(context, viewHolder.imgProduct, (350/(double)750));
        if (AppInfor.getInstance().getUserState() < 2){
            viewHolder.tvOldPrice.setTextColor(ContextCompat.getColor(context, R.color.gray_text));
            viewHolder.tvOldPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
            viewHolder.tvOldPrice.setText("￥" + list.get(i).marketPrice);
        }else {
            viewHolder.tvOldPrice.setTextColor(ContextCompat.getColor(context, R.color.red_bg));
            viewHolder.tvOldPrice.setText("赚" + list.get(i).marketPrice);
        }
        MoHuGlide.getInstance().glideImg(context, list.get(i).productSmallImage, viewHolder.imgProduct);
        viewHolder.tvPrice.setText("￥" + list.get(i).retailPrice);
        viewHolder.tvProduceSolve.setText("已售" + list.get(i).sellCount + "件");
        viewHolder.tvProduce.setText(list.get(i).productName);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, JDGoodinfoActivity.class);
                intent.putExtra(JDGoodinfoActivity.JOIN_TYPE, JDGoodinfoActivity.NOMAL);
                intent.putExtra(JDGoodinfoActivity.PRODUCT_ID, list.get(i).productId);
                if (!(context instanceof Activity)) {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                }
                context.startActivity(intent);
            }
        });
    }

    @NonNull
    @Override
    public ViewHold onCreateBodyViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.pay_result_item, viewGroup, false));
    }
    @Override
    public int getBodyItemCount() {
        return list.size();
    }

    @Override
    public int getBodyItemViewType(int position) {
        return 0;
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.placeholder_view)
        View placeholderView;
        @BindView(R.id.img_product)
        ImageView imgProduct;
        @BindView(R.id.tv_produce)
        TextView tvProduce;
        @BindView(R.id.tv_produce_solve)
        TextView tvProduceSolve;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.tv_old_price)
        TextView tvOldPrice;
        @BindView(R.id.tv_state)
        TextView tvState;
        @BindView(R.id.linear_buy)
        LinearLayout linearBuy;
        @BindView(R.id.parent_ly)
        LinearLayout parentLy;
        private View itemView;

        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }

}
